//// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
//package com.linqingying.gitcode.pullrequest.data
//
//import com.intellij.collaboration.ui.html.AsyncHtmlImageLoader
//import com.intellij.collaboration.ui.icon.IconsProvider
//import com.intellij.openapi.util.Disposer
//import kotlinx.coroutines.CoroutineScope
//import kotlinx.coroutines.Dispatchers
//import kotlinx.coroutines.awaitCancellation
//import kotlinx.coroutines.launch
//import com.linqingying.gitcode.api.data.GCReactionContent
//import com.linqingying.gitcode.api.data.pullrequest.GCPullRequest
//import com.linqingying.gitcode.pullrequest.GCPRDiffRequestModel
//import com.linqingying.gitcode.pullrequest.data.service.*
//import com.linqingying.gitcode.ui.avatars.GCAvatarIconsProvider
//
//internal class GCPRDataContext(val scope: CoroutineScope,
//                               val listLoader: GCPRListLoader,
//                               val listUpdatesChecker: GCPRListUpdatesChecker,
//                               val dataProviderRepository: GCPRDataProviderRepository,
//                               val securityService: GCPRSecurityService,
//                               val repositoryDataService: GCPRRepositoryDataService,
//                               val creationService: GCPRCreationService,
//                               val detailsService: GCPRDetailsService,
//                               val reactionsService: GCReactionsService,
//                               val htmlImageLoader: AsyncHtmlImageLoader,
//                               val avatarIconsProvider: GCAvatarIconsProvider,
//                               val reactionIconsProvider: IconsProvider<GCReactionContent>,
//                               val filesManager: GCPRFilesManager,
//                               val interactionState: GCPRPersistentInteractionState,
//                               val newPRDiffModel: GCPRDiffRequestModel) {
//
//  private val listenersDisposable = Disposer.newDisposable("GC PR context listeners disposable")
//
//  init {
//    listLoader.addDataListener(listenersDisposable, object : GCListLoader.ListDataListener {
//      override fun onDataAdded(startIdx: Int) = listUpdatesChecker.start()
//      override fun onAllDataRemoved() = listUpdatesChecker.stop()
//    })
//    dataProviderRepository.addDetailsLoadedListener(listenersDisposable) { details: GCPullRequest ->
//      listLoader.updateData {
//        if (it.id == details.id) details else null
//      }
//      filesManager.updateTimelineFilePresentation(details)
//    }
//
//    // need immediate to dispose in time
//    scope.launch(Dispatchers.Main.immediate) {
//      try {
//        awaitCancellation()
//      }
//      finally {
//        Disposer.dispose(filesManager)
//        Disposer.dispose(listenersDisposable)
//        Disposer.dispose(dataProviderRepository)
//        Disposer.dispose(listLoader)
//        Disposer.dispose(listUpdatesChecker)
//        Disposer.dispose(repositoryDataService)
//      }
//    }
//  }
//}
